from django.db import models
from django.core import validators


class User(models.Model):
    css_id = models.CharField(max_length=20, verbose_name='工号/学号')
    css_image = models.ImageField(upload_to='user/', max_length=200, default='user/default.png', verbose_name='照片')
    css_name = models.CharField(max_length=20, verbose_name='姓名')
    css_password = models.CharField(max_length=20, verbose_name='密码')
    css_gender = models.CharField(choices=(('female', '女'), ('male', '男')), max_length=10, verbose_name='性别')
    css_role = models.CharField(choices=(('teacher', '教师'), ('student', '学生')), max_length=10, verbose_name='角色')
    css_phone = models.CharField(validators=[validators.RegexValidator(r"1[345678]\d{9}", message='请输入正确格式的手机号码！')],
                                 max_length=20, verbose_name='联系电话', unique=True)
    css_time = models.DateTimeField(auto_now_add=True, verbose_name='注册时间')
    css_school = models.ForeignKey('schools.School', on_delete=models.CASCADE, related_name='student_school',
                                   verbose_name='所属学校')

    def __str__(self):
        return self.css_name

    class Meta:
        ordering = ['id']
        verbose_name = '用户'
        verbose_name_plural = verbose_name
        db_table = 'user'
